﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;

namespace OlapProject
{
    class DatabaseHandler
    {
        public SqlConnection connection;

        public DatabaseHandler () 
        {
            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
            builder["Data Source"] = "(local)";
            builder["integrated Security"] = true;
            builder["Initial Catalog"] = "OLAP";
            connection = new SqlConnection(builder.ConnectionString);
        }

        public void insertRow (PropertyVO property)
        {
            string query = "INSERT INTO temp(country, city, district, price, area, plotArea, type, bedrooms, bathrooms, source, datetime) VALUES(" +
                "@country, @city, @district, @price, @area, @plotArea, @type, @bedrooms, @bathrooms, @source, @datetime" +
            ")";

            SqlCommand cmd = new SqlCommand(query, connection);

            cmd.Parameters.AddWithValue("@country", property.country);
            cmd.Parameters.AddWithValue("@city", property.city);
            cmd.Parameters.AddWithValue("@district", property.district);
            cmd.Parameters.AddWithValue("@price", property.price);
            cmd.Parameters.AddWithValue("@area", property.area);
            cmd.Parameters.AddWithValue("@plotArea", property.plotArea);
            cmd.Parameters.AddWithValue("@type", property.type);
            cmd.Parameters.AddWithValue("@bedrooms", property.bedrooms);
            cmd.Parameters.AddWithValue("@bathrooms", property.bathrooms);
            cmd.Parameters.AddWithValue("@source", property.source);
            cmd.Parameters.AddWithValue("@datetime", property.datetime);

            cmd.ExecuteNonQuery();
        }
    }
}
